package com.net.xpay.core.manager.impl.collect;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.net.xpay.core.constant.TransBizTypeConstant;
import com.net.xpay.core.manager.collect.CollectionSafePayBatchManager;
import com.net.common.annotation.WriteTransactional;
import com.net.common.dao.BasicMapper;
import com.net.noah.core.service.SerialNumberService;
import com.net.xpay.core.dao.collect.CollectionSafePayBatchMapper;
import com.net.xpay.core.domain.collect.CollectionSafePayBatch;
import com.net.common.manager.AbstractVersionedManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;


@Component
public class CollectionSafePayBatchManagerImpl extends AbstractVersionedManager<CollectionSafePayBatch> implements CollectionSafePayBatchManager {

    @Autowired
    private CollectionSafePayBatchMapper mapper;


    @Autowired
    private SerialNumberService serialNumberService;


    @Override
    protected BasicMapper<Long, CollectionSafePayBatch> getMapper() {
        return mapper;
    }

    @Override
    @WriteTransactional(propagation = Propagation.SUPPORTS)
    public int save(CollectionSafePayBatch obj) {
        Preconditions.checkArgument(obj.getId() == null);
        obj.setId(serialNumberService.getLongSerialNumber(getTableFullName()));
        obj.setBizId(TransBizTypeConstant.CB_SP + obj.getId());
        return super.save(obj);
    }

    @Override
    public CollectionSafePayBatch findByBizId(Long userId, String bizId) {
        Preconditions.checkArgument(userId != null && !Strings.isNullOrEmpty(bizId));
        CollectionSafePayBatch condition = new CollectionSafePayBatch();
        condition.setBizId(bizId);
        return getByCondition(condition);
    }
}
